Stored Procedures [dbo].[asi_UserMainLogin]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@ProviderKeynvarchar(100)200
SQL Script
CREATE      PROC [dbo].[asi_UserMainLogin]
    @ProviderKey nvarchar(100)
    AS
BEGIN
    -- Set nocount option to surpress row count messages
    SET NOCOUNT ON
    -- Declare variables
    DECLARE @UserKey uniqueidentifier
    DECLARE @ContactMaster varchar(50)
    DECLARE @Name nvarchar(50)
    DECLARE @UserIdTest nvarchar(50)
    DECLARE @OrganizationKey uniqueidentifier
    DECLARE @LoggedInUserGroupKey uniqueidentifier
    -- Set rowcount option to only allow a single row in the resultset
    SET ROWCOUNT 1

    -- Initialize local variables if User/Password combination is valid and user is active
    SELECT    @UserKey = UserMain.UserKey,
        @ContactMaster = UserMain.ContactMaster,
        @Name = UserMain.UserId,
        @UserIdTest = UserMain.UserId
     FROM    UserMain
     WHERE    UserMain.ProviderKey = @ProviderKey
       AND    UserMain.IsDisabled = 0
       AND    COALESCE(UserMain.EffectiveDate,DATEADD(day,-1,getdate())) <= GETDATE()
       AND    COALESCE(UserMain.ExpirationDate,DATEADD(day,1,getdate())) >= GETDATE()

    SELECT @OrganizationKey = OrganizationKey
    FROM OrganizationMain
    WHERE IsDefault = 1

    -- Reset rowcount option to allow multiple rows in resultset
    SET ROWCOUNT 0
    -- If validation succeeded, then continue
    IF @UserKey IS NOT NULL
    BEGIN
        -- Return variables as first resultset
        SELECT    @UserKey AS UserKey,
            @ContactMaster AS ContactMaster,
            @Name AS Name,
            @UserIdTest AS UserId,
            @OrganizationKey AS OrganizationKey
        -- Return roles as second resultset
        EXEC asi_UserTokenUpdate @UserKey
        -- Return legacy roles as third resultset
        SELECT * from vLegacySecurityRole where UserKey = @UserKey
        
        SELECT @LoggedInUserGroupKey = ParameterValue
          FROM SystemConfig WHERE ParameterName = 'CM.LoggedInUserGroupKey'
        
        SELECT GroupKey, [Name]
          FROM GroupMain WHERE GroupKey = @LoggedInUserGroupKey
    END

    -- Reset nocount option
    SET NOCOUNT OFF

END

GO
Uses